package com.itheima.manager;

import com.itheima.common.R;
import com.itheima.domain.Resource;
import com.itheima.service.IResourceService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UmsResourceManager {
    @DubboReference
    IResourceService resourceService;

    //根据条件分页模糊查询资源
    public R<PageBeanVo> findByConditionAndPage(Integer pageNum, Integer pageSize, String nameKeyword, String urlKeyword, String categoryId) {
        PageBeanVo pageBeanVo=resourceService.findByConditionAndPage(pageNum,pageSize,nameKeyword,urlKeyword,categoryId);
        return R.success(pageBeanVo);
    }

    //查询所有
    public R<List<Resource>> findAll() {
        List<Resource> list=resourceService.findAll();
        return R.success(list);
    }

    //修改后台资源
    public R<String> updateResource(Resource resource) {
        resourceService.updateResource(resource);
        return R.success("修改资源成功");
    }

    public R<Resource> findById(Long id) {

        Resource resource=resourceService.findById(id);
        return R.success(resource);
    }

    //添加后台资源
    public R<String> saveResource(Resource resource) {
        resourceService.saveResource(resource);
        return R.success("添加成功");
    }

    //根据id删除资源
    public R<String> deleteResource(Long id) {
        resourceService.deleteResource(id);
        return R.success("删除成功");
    }
}
